package WorkTask2;

import java.util.*;

/*
使用集合实现斗地主游戏的部分功能，要求如下：
     *
     *  （1）首先准备 54 张扑克牌并打乱顺序。
     *
     *  （2）由三个玩家交替摸牌，每人 17 张扑克牌，最后三张留作底牌。
     *
     *  （3）查看三个玩家手中的扑克牌和底牌。
     *
     *  （4）其中玩家手中的扑克牌需要按照大小顺序打印，规则如下：
     *
     *     手中扑克牌从大到小的摆放顺序：大王,小王,2,A,K,Q,J,10,9,8,7,6,5,4,3
 */
public class PokerGame{
    public static void main(String[] args) {
        String[] shape = {"♠","♠","♣","♦"};
        String[] order = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
        List<String> pokerList = new ArrayList<>();
        for (String s:order){
            for (String s2:shape){
                pokerList.add(s + s2);
            }
        }
        pokerList.add("大王");
        pokerList.add("小王");

        System.out.println(pokerList.toString());
        Collections.shuffle(pokerList);
        System.out.println(pokerList);

        List<String> player1 = new ArrayList<>();
        List<String> player2 = new ArrayList<>();
        List<String> player3 = new ArrayList<>();
        List<String> restPoker = new ArrayList<>();

        for (int i = 0; i < pokerList.size(); i++) {
            if (i >= 51){
                restPoker.add((String) ((List<?>) pokerList).get(i));
            }else if (0 == i%3){
                player1.add( pokerList.get(i));
            }else if (1 == i%3){
                player2.add(pokerList.get(i));

            }else {
                player3.add(pokerList.get(i));
            }

        }
        Collections.sort(player1);
        Collections.reverse(player1);
        Collections.sort(player2);
        Collections.reverse(player2);
        Collections.sort(player3);
        Collections.reverse(player3);
        System.out.println("player1:" + player1);
        System.out.println("player2:" + player2);
        System.out.println("player3:" + player3);
        System.out.println("restPoker:" + restPoker);

    }


}
